<?php

/**
 * 公众号通用 以后的只要配置/confing/weChatOptions.php和global.php的里域名
 * Created by PhpStorm.
 * User: wyr
 * Date: 14-10-8
 * Time: 下午9:17
 */
class Controller_Www_Abstract extends FController
{

    public function beforeAction()
    {
        global $_F;

        /*if ($this->is_weixin() === false) {
            $controller = strtolower($_F['action']);
            if ($controller == 'lettershow' || $controller == 'download') {

            } else {
                die('请在微信客户端打开链接');
            }
        }*/

        $_F['s_url'] = 'http://img1.yuanfenba.net';
        $_F['s_url_oss'] = 'http://image1.yuanfenba.net'; //FConfig::get('global.s_url_oss');

        return true;
    }

    function showMessage($message, $msgType, $url = null)
    {
        echo "<script>alert('{$message}');";
        if ($url) echo "location='{$url}';";
        echo "</script>";
    }

    /**
     * 判断是否为微信，是微信就用微信登录，不是就是wap
     * @return bool
     */
    protected function is_weixin()
    {
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
            return true;
        }
        return false;
    }

    /**
     * 是否已关注
     * @return bool true 为已关注
     */
    protected function isSubscribe()
    {
        global $_F;
        $openid = $_F['openid'];
        if ($this->is_weixin()) {
            if ($openid) {
                return Service_UserApi2::isSubscribe($openid);
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    /**不否为苹果系统
     * @return bool true是，false否
     */
    protected function is_ios()
    {
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
            return true;
        } else {
            return false;
        }
    }
}
